package de.eventdroid.helper_classes;

import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Texthandler {
	
	/**
	 * Empty Constructor for getting Object Access to the Methods
	 */
	public Texthandler() {
	}
	
	/**
	 * This Method replaces the Umlaut Placeholder Code to real Umlauts 
	 * for Visualisation on the Phone
	 * 
	 * @param actString String with replacecode for the Umlauts
	 * @return String with Umlauts
	 */
	public static String replaceUmlauts(String actString) {
		
		/* String Arrays in which the  */
		String[] umlautsHTML = {"&auml;", "&Auml;", "&ouml;", "&Ouml;", "&uuml;", "&Uuml;", "&szlig;"};
		String[] umlautReplaceCodes = {"&#228;", "&#246;", "&#252;", "&#196;", "&#214;", "&#220;", "&#223;"};
		String[] umlautsUTF = {"ä", "Ä", "ö", "Ö", "ü", "Ü", "ß"};
		
		for(int i = 0; i<umlautReplaceCodes.length; i++) {
			actString = actString.replace(umlautsHTML[i],umlautsUTF[i]);
		}		
		
		return actString;
		
	}
	
	/**
	 * Extracts the IDs from the results
	 * @param actRessources
	 * @return the ids of the resultset
	 */
	public static ArrayList<String> extractIDFromResultArray(ArrayList<String> actResults ) {
		
		ArrayList<String> resultIds = new ArrayList<String>();
		StringTokenizer resultIdTokenizer = null;

		for(int i = 0; i < actResults.size(); i++)
		{
			resultIdTokenizer = new StringTokenizer(actResults.get(i), "#");
			resultIds.add(resultIdTokenizer.nextToken());
		}
		
		return resultIds;
		
	}
	
	/**
	 * Cleanup the ArrayList from the Ids for printout
	 * @param actRessources
	 * @return the list without the ids
	 */
	public static ArrayList<String> cleanUpArrayFromIds (ArrayList<String> actResults ) {
		
		ArrayList<String> cleanedList = new ArrayList<String>();
		StringTokenizer resultIdTokenizer = null;

		for(int i = 0; i < actResults.size(); i++)
		{
			resultIdTokenizer = new StringTokenizer(actResults.get(i), "#");
			resultIdTokenizer.nextToken();
			cleanedList.add(resultIdTokenizer.nextToken());
		}
		
		return cleanedList;
		
	}

}
